<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑权限</title>
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.5.5/css/layui.css}"
          href="../../../static/layuimini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" href="../../../static/layuimini/css/public.css"
          media="all">
    <style>
        body {
            background-color: #fff;
            padding: 0;
            margin: 0;
        }

        body .layui-layer-btn {
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
            padding-top: 10px;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <form id="permissionInfoForm">
        <div class="layui-form-item"></div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限名称：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="perName" th:value="${sysPermission!=null?sysPermission.perName:''}"
                       lay-verify="required" placeholder="权限名称" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid" style="color: red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限标识：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="perFlag" th:value="${sysPermission!=null?sysPermission.perFlag:''}"
                       lay-verify="required" placeholder="权限标识" autocomplete="off" th:readonly="${sysPermission!=null}"
                       class="layui-input">

            </div>
            <div class="layui-form-mid" style="color: red">*</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">访问地址：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="url" th:value="${sysPermission!=null?sysPermission.url:''}"
                       placeholder="请输入相对url" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">资源图标：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" name="icon" th:value="${sysPermission!=null?sysPermission.icon:''}"
                       placeholder="请输入图标标识" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item">
            <label class="layui-form-label">目标类型：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="radio" name="targetType" value="1" title="_self"
                       th:checked="${sysPermission==null||sysPermission.targetType==1}">
                <input type="radio" name="targetType" value="2" title="_blank"
                       th:checked="${sysPermission!=null&&sysPermission.targetType==2}">
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">父级资源：</label>
            <div class="layui-input-inline" style="width: 320px;">
                <input type="text" placeholder="无父级，将存为模块" autocomplete="off"
                       class="layui-input" th:value="${parentSysPermission!=null?parentSysPermission.perName:''}"
                       readonly>
                <input type="hidden" name="parentId"
                       th:value="${parentSysPermission!=null?parentSysPermission.perId:''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">权限描述：</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" name="perDesc" style="width: 320px;"
                          th:text="${sysPermission!=null?sysPermission.perDesc:''}"></textarea>
            </div>
        </div>
        <div class="layui-layer-btn layui-layer-btn-">
            <a id="per_save" class="layui-layer-btn0" lay-filter="btn_save" lay-submit>保存</a>
            <a id="edit_cancel" class="layui-layer-btn1">关闭</a>
        </div>
        <!--隐藏域-->
        <input type="hidden" name="targetType" value="1">
        <input id="perId" type="hidden" name="perId" th:value="${param.perId}">
    </form>
</div>

<script th:src="@{/layuimini/lib/layui-v2.5.5/layui.js}" src="../../../static/layuimini/lib/layui-v2.5.5/layui.js"
        charset="utf-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" src="../../../static/layuimini/js/lay-config.js?v=1.0.4"
        charset="utf-8"></script>
<script th:inline="text">
    layui.use(['form', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;


        /*$('#per_save').click(function () {
            save();
        });*/


        form.on('submit(btn_save)',function (){
            save();
            return false;
        })
        //保存
        function save() {
            var permissionData = $('#permissionInfoForm').serialize();
            console.log(permissionData);
            layer.load(2);
            $.ajax({
                type: 'post',
                url: '[[@{/}]]manage/permission/permissionSave',
                data: permissionData,
                dataType: 'json',
                success: function (result) {
                    console.log(result);
                    if (result.success){
                        layer.msg("保存成功");
                        $('#perId').val(result.data.perId);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    layer.msg(textStatus);
                },
                complete: function () {
                    layer.closeAll('loading');
                }
            });
        }

        //取消
        $('#edit_cancel').click(function cancel() {

            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

        form.render();
    });
</script>
</body>
</html>